package com.lbd.system.service.impl;

import com.lbd.base.service.BaseServiceImpl;
import com.lbd.system.bean.RecordProperty;
import com.lbd.system.dao.RecordPropertyRepository;
import com.lbd.system.service.RecordPropertyService;
import org.apache.log4j.Logger;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * Created by WangYajie on 2016/9/19.
 */
@Service
@Transactional
public class RecordPropertyServiceImpl extends BaseServiceImpl<RecordProperty, RecordPropertyRepository> implements RecordPropertyService {
    private final Logger log = Logger.getLogger(this.getClass());
    @Resource
    RecordPropertyRepository recordPropertyRepository;

    @Override
    public Specification<RecordProperty> getSpecification(RecordProperty recordProperty) {
        return null;
    }

    /**
     * 构建交易记录的查询条件和参数
     *
     * @param record
     * @param parameter(用户名|电话)
     * @return
     */
    @Override
    public String buildJpql(RecordProperty record, Map<String, Object> parameter) {
        StringBuilder jpqlBuilder = new StringBuilder("  from  RecordProperty t   ");
        if (record != null) {
           /* if (record.getUser() != null) {
                if (StringUtils.isNotBlank(record.getUser().getName())) {
                    jpqlBuilder.append(" and  t.user.name like :name");
                    parameter.put("name", "%" + record.getUser().getName() + "%");
                }
                if (StringUtils.isNotBlank(record.getUser().getTelephone())) {
                    jpqlBuilder.append(" and  t.user.telephone like :telephone");
                    parameter.put("telephone", "%" + record.getUser().getTelephone() + "%");
                }
            }*/
        }
        jpqlBuilder.append(" ORDER BY t.createdDate DESC ");
        return jpqlBuilder.toString();
    }

    @Override
    public List<RecordProperty> findByRecordId(String recordId) {
        return recordPropertyRepository.findByRecordId(recordId);
    }
}
